package com.example.service.Impl;

import com.example.mapper.VipMapper;
import com.example.pojo.Vip;
import com.example.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.List;

/**
 * @author LinJie
 * @create 2020-12-11 14:19
 */
@Service
public class VipServiceImpl implements VipService {

    @Autowired
    private VipMapper vipMapper;

    @Override
    public List<Vip> queryAll() {
        return vipMapper.queryAll();
    }

    @Override
    public int addVip(Vip vip) {
        Vip vipcheck = vipMapper.queryVip(Integer.parseInt(vip.getVip_id()));
        if (vipcheck == null) {
            //此编号可以使用
            return vipMapper.addVip(vip);
        } else {
            //此编号不为空，不能添加
            return -1;
        }
    }

    @Override
    public int updateVip(Vip vip) {
        return vipMapper.updateVip(vip);
    }

    @Override
    public int deleteVip(int vip_id) {
        return vipMapper.deleteVip(vip_id);
    }

    @Override
    public Vip queryVip(int vip_id) {
        return vipMapper.queryVip(vip_id);
    }

    @Override
    public int verifyVip(String userId, String telephone) {
        //检验ID和电话号码
        Vip vipId = vipMapper.verifyVipByid(userId);
        Vip vipTele = vipMapper.verifyVipBytele(telephone);
        //输出一下信息
        System.out.println("vipid" + vipId);
        System.out.println("viptele" + vipTele);

        if (vipId != null && vipTele != null) {
            //会员存在
            return 1;
        } else if (vipId == null && vipTele != null) {
            //会员id不存在
            return -1;
        } else if (vipTele == null && vipId != null) {
            //会员电话号不存在
            return -2;
        } else {
            //会员id和会员电话号都不存在
            return -3;
        }
    }
}
